package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.OtherStudentDao;
import com.itheima.edu.info.manager.domain.Student;

import java.util.Scanner;

public class StudentService {
    private OtherStudentDao otherStudentDao = new OtherStudentDao();
    Student stu = new Student();
    Scanner sc = new Scanner(System.in);

    public boolean addStudent(Student stu) {
        boolean result = otherStudentDao.addStudent(stu);
        return result;
    }

    public boolean isExists(String sid) {
        Student[] stuArr = otherStudentDao.getStuArr();
        boolean result = false;
        for (int i = 0; i < stuArr.length; i++) {
            Student stu = stuArr[i];
            if(stu != null && sid.equals(stu.getId())){
                result = true;
            }
        }
        return result;
    }

    public Student[] findAllStudent() {
        Student[] stuArr = otherStudentDao.getStuArr();
        for (int i = 0; i < stuArr.length; i++) {
            if(stuArr[i] != null){
                return stuArr;
            }
        }
        return null;
    }

    public void deleteStudentById(String id) {
        otherStudentDao.deleteStudentById(id);
    }

    public void updateStudent(String id,Student stu) {
        otherStudentDao.updateStudent(id,stu);
    }
}
